package com.yzt.rabbitmq.consumer;

import java.util.Map;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import com.rabbitmq.client.Channel;

@Component
public class RabbitMQConsumer {

	@RabbitListener(queues = "DEFAULT_QUEUE")
	public void received(Message message, Channel channel) throws Exception {
		System.out.println("-----接收消息----");
		String msg = new String(message.getBody(), "UTF-8");
		String id = message.getMessageProperties().getMessageId();
		System.out.println("接收到消息:" + id + "\t" + msg);
	}
	
	@RabbitListener(queues = "DEFAULT_QUEUE")
	public void received2(@Payload String body,@Headers Map<String,Object> headers) {
		System.out.println("-----接收消息2----");
		System.out.println(body);
		System.out.println(headers);
	}
}
